/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Initial Developer of the Original Code is
*   Nick Kreeger
* Portions created by the Initial Developer are Copyright (C) 2006-2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*   Nick Kreeger <nick.kreeger@park.edu>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */

#import <Cocoa/Cocoa.h>

@class MailboxItem;
@class CHBrowserView;
@class DummyMessageHeader;
@class MessageHeader;
@class MailWindowController;
@class MessageWindowController;
class CHMsgService;
class nsIMsgWindow;

@protocol MessageWindowDelegate <NSObject>

-(void)onMessageLoaded:(DummyMessageHeader*)aDummyMessageHeader;
-(void)onAttachmentsLoaded:(NSArray*)aAttachmentArray;
-(CHBrowserView*)browserMessageView;

@end

@protocol MessageDataDelegate <NSObject>

-(void)onTotalMessagesChanged;
-(void)onTotalUnreadMessagesChanged;
-(void)onNewMailBiffStateChanged;
-(void)onStartTransmission;
-(void)onStopTransmission;
-(void)onStatusMessageUpdated:(NSString*)aStatusMessage;

@end

/**
 * Global class to maintain information consitency between the cocoa
 * UI layers and the low end mailnews and gecko layers.
 */
@interface MessageWindowService : NSObject <MessageWindowDelegate, MessageDataDelegate>
{
@private
  CHMsgService*             mMsgService;                // strong
  NSMutableArray*           mMailWindowControllers;     // strong
  NSMutableArray*           mMessageWindowControllers;  // strong
  
  id<MessageWindowDelegate> mMessageWindowDelegate;     // weak, the current window
  
  NSString*                 mCurrentMessageUri;
  BOOL                      mIsMessageLoading;
  BOOL                      mIsTransmitting;
}

/**
 * Get the global instance of this class.
 * @return The shared instance of this class.
 */
+(id)sharedInstance;

/**
 * Create an instance of the mail window and show it. This is the window
 * that contains the folder list, message list, and messave view.
 */
-(void)createAndShowMailWindowController;

/**
 * Get the current mail window controller.
 * @return The current mail window controller, or nil if one does not exist.
 */
-(MailWindowController*)currentMailWindowController;

/**
 * Set the message window delegate object. This object will be 
 * notified of any message events from mailnews.
 *
 * Anytime a window message or mail window obtains focus, this
 * method needs to be called so that that window becomes the 
 * window that receives the message window events from gecko.
 *
 * @param aDataDelegate - The delegate to receive the messages.
 */
-(void)setMessageWindowDelegate:(id<MessageWindowDelegate>)aDelegate;

/**
 * Initialize an embedded view with the mailnews session.
 * @param aBrowserView The browser view to use for mail viewing.
 */
-(void)initMessageWindow:(CHBrowserView*)aBrowserView;

/**
 * This method will notify mailnews that the window containing the
 * browser view will be closing. This will ensure that notifications
 * are not getting sent to the window.
 * @param aMessageWinController The message window to remove.
 */
-(void)removeMessageWindow:(MessageWindowController*)aMessageWinController;

/**
 * Get the |nsIMsgWindow| instance for a browser view. The browser view
 * needs to have been intialized with |initMessageWindow:| in order
 * to retrieve a value.
 *
 * Kreeger: As of 0.2, this method is incomplete and not used.
 *
 * @param aBrowserView The browser view to look up with.
 * @return The associated message window for the browserview, or nsnull
 *         if a view can not be determined.
 */
-(nsIMsgWindow*)messageWindowForBrowserView:(CHBrowserView*)aBrowserView;

/**
 * Get the |nsIMsgWindow| instance that is the most focused window. If
 * there is a scenario where there is not a way to tell the top-most 
 * window, the first created instance is returned.
 * @return The top-most message window.
 */
-(nsIMsgWindow*)getTopmostMsgWindow;

/**
 * Open a message window with a given URI.
 * @param aMessageHeader The message header of the desired message to load.
 * @param aUri The URI of the message to load.
 * @param aCharSet The character set of the message URI, or nil if one 
 *                 does not exist or is unkown.
 */
-(void)openMessageWindowWithMessageHeader:(MessageHeader*)aMessageHeader 
                            messageUri:(NSString*)aUri
                          andCharacterSet:(NSString*)aCharSet;

/**
 * Load a message given the URI of the message.
 * @param aMessageUri The URI of the message to load.
 */
-(void)loadMessageUri:(NSString*)aMessageUri;

/**
 * Get new messages for an individual mailbox item.
 * @param aMailboxItem The mailbox item to get new messages for.
 */
-(void)getNewMessagesForMailboxItem:(MailboxItem*)aMailboxItem;

/**
 * Get new messages for an array of mailbox objects. 
 * @param aMailboxArray The array of mailboxes to get new mail for.
 * 
 * @comments:
 *  - kreeger: This doesn't work yet and will do nothing (Mar. 12, 2007)
 */
-(void)getNewMessagesForMailboxItems:(NSMutableArray*)aMailboxArray;

/**
 * Stop any actively running URL/URI in a mailnews session.
 */
-(void)stopActiveUrl;

/**
 * @return If the mailnews session is running a URL/URI.
 */
-(BOOL)isRunningUrl;

/**
 * @return If a folder is transmitting messages.
 */
-(BOOL)isTransmitting;

/**
 * @return The current loaded message URI or nil if there is not a loaded message.
 */
-(NSString*)currentMessageUri;

@end
